package com.example.ijkplayertest

import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TableLayout
import com.example.ijkplayertest.media.IjkVideoView
import tv.danmaku.ijk.media.player.IjkMediaPlayer

class MainActivity : AppCompatActivity() {
    val videoUrl = "rtmp://192.168.100.215:1935/rtmplive/room"
    lateinit var mVideoView:IjkVideoView
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // init player
        IjkMediaPlayer.loadLibrariesOnce(null)
        IjkMediaPlayer.native_profileBegin("libijkplayer.so")
        setContentView(R.layout.activity_main)
        mVideoView = findViewById(R.id.video_view)
        val hudview : TableLayout = findViewById(R.id.hud_view)
//        mVideoView.setVideoURI(Uri.parse(videoUrl))
        mVideoView.setHudView(hudview)
        mVideoView.setVideoPath(videoUrl)
        mVideoView.start()
    }
    override fun onStop() {
        super.onStop()
        if ( !mVideoView.isBackgroundPlayEnabled()) {
            mVideoView.stopPlayback()
            mVideoView.release(true)
            mVideoView.stopBackgroundPlay()
        } else {
            mVideoView.enterBackground()
        }
        IjkMediaPlayer.native_profileEnd()
    }
}